package com.csw.springd.interceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginInteceptor  implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
        System.out.println("----enter interceptor----");
        String loginName = (String) request.getSession().getAttribute("loginName");
        if (!StringUtils.isEmpty(loginName)) {
            return  true;
        }
        request.getRequestDispatcher("/index.html").forward(request, response);
        return false;
    }
}
